// App.js
import React, { useState, useEffect } from 'react';

const App = () => {
  const [result, setResult] = useState('');
  const useRefObj = React.useRef();
  useEffect(() => {
    const worker = new Worker(
      new URL('./worker.js', import.meta.url)
    );

    worker.onmessage = (event) => {
      setResult(event.data);
    };
    useRefObj.current = worker;

  }, [])

  return (
    <div>
      <button onClick={() => {
        useRefObj.current.postMessage({ startValue: 1, endValue: 100 });
      }
      }>大量计算</button>
      <input type="text" />
      <p>Result: {result}</p>
    </div>
  );
};

export default App;
